package cn.enilu.flash.mobile.controller;

import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.entity.bus.Collection;
import cn.enilu.flash.bean.entity.bus.Enterprise;
import cn.enilu.flash.bean.vo.front.Rets;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.mobile.domain.EnterpriseDomain;
import cn.enilu.flash.service.bus.CollectionService;
import cn.enilu.flash.service.bus.EnterpriseService;
import cn.enilu.flash.utils.factory.Page;
import cn.enilu.flash.web.controller.BaseController;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;
import java.util.List;


@RestController
@RequestMapping("/enterprise")
public class EnterpriseController extends BaseController {

    @Autowired
    private EnterpriseService enterpriseService;

    @Autowired
    private CollectionService collectionService;

    @GetMapping(value = "/list")
    public Object list() {
        Page<Enterprise> page = new PageFactory<Enterprise>().defaultPage();
        page = enterpriseService.queryPage(page);
        return Rets.success(page);
    }

    @GetMapping(value = "/{id}")
    public Object getInfoById(@PathVariable("id") Long id) {
        EnterpriseDomain enterpriseDomain = new EnterpriseDomain();
        Enterprise enterprise = enterpriseService.get(id);
        try {
            BeanUtils.copyProperties(enterpriseDomain, enterprise);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        return Rets.success(enterpriseDomain);
    }

}
